﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VoiceAI;
using VoiceAI.VoiceResponse;
using Windows.Foundation.Collections;

namespace Xiaowei.ResponseHandlers
{
    internal static class AlarmResponseHandler
    {
        public static void Handle(IResponseData responseData)
        {
            if(responseData is IAlarmResponseData alarmResponse)
            {
                foreach (var item in alarmResponse.Clock_info)
                {
                    ValueSet alarmOperation = new ValueSet();
                    alarmOperation["Request"] = "AlarmOperation";
                    alarmOperation["opt"] = (int)item.ClockOpt;
                    alarmOperation["Clock_id"] = item.Clock_id;
                    alarmOperation["Clock_event"] = item.Clock_event;
                    alarmOperation["Repeat_interval"] = item.Repeat_interval;
                    alarmOperation["Repeat_type"] = (int)item.Repeat_type;
                    alarmOperation["Service_type"] = item.Service_type;
                    alarmOperation["Trig_time"] = item.Trig_time;

                    Services.AppServiceManager.Instance.SendMessage(alarmOperation);
                    if(item.ClockOpt== ClockOpt.Add)
                    {
                        alarmResponse.DataContext = new Models.ClockModel {
                            Event = item.Clock_event,
                            Time= DateTimeOffset.FromUnixTimeSeconds(item.Trig_time).ToLocalTime().TimeOfDay.ToString()

                    };
                    }
                }
            }
            DefaultResponseHandler.Handle(responseData);
        }
    }
}
